/**
 * 表单设计--参照
 */

mini.parse();

var grid1 = mini.get("grid1");
var grid2 = mini.get("grid2");
//mini.get("sp").set({
//    height : document.body.clientHeight - 40
//});
var set;
var referData = [];
function init() {
     $.ajax({
        type : 'POST',
        url : ajaxUrl + "/formList/list.do",
        dataType : 'json',
        contentType: "application/json",
        success: function (data) {
            console.log(data);
            grid1.setData(data.data);

        },
        error: function () {
            mini.alert('获取失败！');
        }
    })
}
function onSelectionChanged(e) {

    var grid = e.sender;
    var record = grid.getSelected();
    if (record) {
        $.ajax({
            type : 'POST',
            url : ajaxUrl + "/formltems/cFileIdList.do?formId="+record.formListId,
            // url : "http://localhost:8080/bpm/formltems/findByFormListId.do?formId=48",
            dataType : 'json',
            contentType: "application/json",
            success: function (data) {
                console.log(data);
                grid2.setData(data.data);
                $.ajax({
                    type : 'POST',
                    url : ajaxUrl + "/classTable/findByTableName.do?tableName="+record.cTableName,
                    dataType : 'json',
                    contentType: "application/json",
                    success: function (rData) {
                    	referData = rData.data;
                    },
                    error: function () {
                        mini.alert('获取失败！');
                    }
                })
            },
            error: function () {
                mini.alert('获取失败！');
            }
        })
    }
}
function SetData(data) {
    set = mini.clone(data);
    console.log(set);
    init();
}

//确定按钮之前
function onTableOk() {
    // selected = tree.getSelectedNode();
    // console.log(selected);
    var record = grid2.getSelected();
    if(clearFlag) {
        return "";//重置
    }else {
        if(record) {
            return {record: record, referData:referData}; //返回选中的数据给父组件
        }else {
            mini.alert('请选择参照！');
            return;
        }
    }
}
//父节点禁选
function onBeforeNodeSelect(e) {
    var tree = e.sender;
    var node = e.node;
    if (tree.hasChildren(node)) {
        e.cancel = true;
    }
}
//确定按钮
function onOk(e) {
   CloseWindow("ok");
}
//取消按钮
function onCancel(e) {
    CloseWindow("cancel");
}

//重置按钮
var clearFlag = false;
function clearRef(e) {
    clearFlag = true;
    CloseWindow("ok");
}

function CloseWindow(action) {

    if (window.CloseOwnerWindow)
        return window.CloseOwnerWindow(action);
    else
        window.close();
}
